;; import lists/insertion-sort.scm files/words.scm files/count.scm

(define (list->string chrs)
  (let ((l (length chrs)))
    (let ((s (make-string l #\?)))
      (let loop ((i 0) (chrs chrs))
        (if (null? chrs)
            s
            (begin
              (string-set! s i (car chrs))
              (loop (+ i 1) (cdr chrs))))))))

(include "test/supporting/insertion-sort.scm")
(include "test/supporting/words.scm")
(include "test/supporting/count.scm")

(define file "test/data/alice.txt")
(define (write-line x) (begin (display x) (newline)))
(define (call-with-input-file f p)
  (p (open-input-port f)))
(define (write-line x) (begin (display x) (newline)))

(define main
  (for-each write-line
	    (sort-by (comparing < cdr)
		     (call-with-input-file file count-words))))
